﻿#region << 版 本 注 释 >>
/*----------------------------------------------------------------
// Copyright (C) 2017 ZyCoder
// 版权所有。 
//
// 文件名：LoggerFactory
// 
// 创建者：名字 (zycoder)
// 时间：2018/2/25 16:38:01
//
// 版本：V1.0.0
// 网站: http://www.cnblogs.com/zycoder
//----------------------------------------------------------------*/
#endregion

using System;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace yunlive.Infrastructure.Logger
{
    /// <summary>
    /// 日志工厂类
    /// </summary>
    public  class LoggerFactory : ILogger
    {
        #region 单利
        /// <summary>
        /// 线程锁
        /// </summary>
        private static object lockObj = new object();
        /// <summary>
        /// 日志工厂实例
        /// </summary>
        private static LoggerFactory _Instance;
        /// <summary>
        /// 日志工厂属性 单利
        /// </summary>
        public static LoggerFactory Instance
        {
            get
            {
                if (_Instance == null)
                {
                    lock (lockObj)
                    {
                        if (_Instance == null)
                        {
                            _Instance = new LoggerFactory();
                        }
                    }
                }
                return _Instance;
            }
        }
        #endregion

        /// <summary>
        /// 日志提供者
        /// </summary>
        private ILogger iLogger;

        /// <summary>
        /// 构造函数 生成对象
        /// </summary>
        private LoggerFactory()
        {
            string type = ConfigurationManager.AppSettings["LogType"] ?? "file";
            switch (type)
            {
                case "file":
                    break;
                case "nlog":
                    break;
                default:
                    throw new Exception("日志配置出现异常！");
            }
        }

        #region 接口方法实现 记录日志
        public void Log_Debug(string msg)
        {
            iLogger.Log_Debug(msg);
        }

        public void Log_Exception(Exception ex)
        {
            iLogger.Log_Exception(ex);
        }

        public void Log_Info(string msg)
        {
            iLogger.Log_Info(msg);
        }

        public void Log_Warn(string msg)
        {
            iLogger.Log_Warn(msg);
        }

        public ILogger SetPath(string path)
        {
            iLogger.SetPath(path);
            return iLogger;
        } 
        #endregion
    }
}
